<template>
        <el-card shadow="never" style="max-height: 70vh; overflow: auto">
            <el-form ref="form" :model="form" :rules="rules" label-width="120px" :disabled="disabled">
                <el-form-item label="id:" prop="id" v-show="false">
                    <el-input v-model="form.id" disabled />
                </el-form-item>
                <el-form-item label="订单编号:" prop="sn">
                    <el-input v-model="form.sn" placeholder="请输入订单编号" clearable />
                </el-form-item>
                <el-form-item label="所属用户:" prop="user_id">
                    <SelectPage v-model="form.user_id" :url="'/admin/user/selectPage'" placeholder="请选择所属用户" show_field="nickname" show_id="uid" query_field="uid" :multiple="false" />
                </el-form-item>
                <el-form-item label="类型:" prop="type">
                    <el-select v-model="form.type" placeholder="请选择类型" clearable>
                        <el-option v-for="(item, index) in type" :key="index" :label="item.label" :value="item.value" />
                    </el-select>
                </el-form-item>
                <el-form-item label="扩展数据json:" prop="extra">
                    <el-input v-model="form.extra" placeholder="请输入扩展数据json" clearable />
                </el-form-item>
                <el-form-item label="创建时间:" prop="created_at">
                    <el-date-picker v-model="form.created_at" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择创建时间" />
                </el-form-item>
                <el-form-item label="更新时间:" prop="updated_at">
                    <el-date-picker v-model="form.updated_at" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择更新时间" />
                </el-form-item>
                <el-form-item label="支付时间:" prop="pay_at">
                    <el-date-picker v-model="form.pay_at" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择支付时间" />
                </el-form-item>
                <el-form-item label="是否支付:" prop="is_pay">
                    <el-radio-group v-model="form.is_pay">
                        <el-radio v-for="(item, index) in is_pay" :key="index" :label="item.value">{{ item.label }}</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="总价:" prop="total_price">
                    <el-input-number v-model="form.total_price" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="状态:" prop="status">
                    <el-select v-model="form.status" placeholder="请选择状态" clearable>
                        <el-option v-for="(item, index) in status" :key="index" :label="item.label" :value="item.value" />
                    </el-select>
                </el-form-item>
                <el-form-item label="备注:" prop="remark">
                    <el-input v-model="form.remark" placeholder="请输入remark" clearable />
                </el-form-item>
                <el-form-item label="过期时间:" prop="expire_time">
                    <el-date-picker v-model="form.expire_time" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择过期时间" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm">确认 </el-button>
                    <el-button type="warning" @click="cancel">取消 </el-button>
                </el-form-item>
            </el-form>
        </el-card>
</template>

<script>
import { regionData } from 'element-china-area-data'
export default {
    name: 'EditForm',
    props: {
        findFormData: {
            type: Object,
            default: {}
        },
        editFormParams: {
            type: Object,
            default: {}
        },
        // 表单是否禁用
        disabled: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            // 编辑表单验证规则
            rules: {
                sn: [{ required: true, message: "请输入订单编号", trigger: "blur" }],
                user_id: [{ required: true, message: "请输入所属用户", trigger: "blur" }],
                extra: [{ required: true, message: "请输入扩展数据json", trigger: "blur" }],
                created_at: [{ required: true, message: "请输入创建时间", trigger: "blur" }],
                updated_at: [{ required: true, message: "请输入更新时间", trigger: "blur" }],
                is_del: [{ required: true, message: "请输入是否删除", trigger: "blur" }],
                is_pay: [{ required: true, message: "请输入是否支付", trigger: "blur" }],
                total_price: [{ required: true, message: "请输入总价", trigger: "blur" }],
                status: [{ required: true, message: "请输入状态", trigger: "blur" }],
                remark: [{ required: true, message: "请输入remark", trigger: "blur" }],

            },
            form: {  },
            // 区域选择配置
            areaOptions: regionData,
            type:[
               { label: "专家咨询", value: 1 },
               { label: "直播间", value: 2 },
               { label: "购买服务", value: 3 },
               { label: "需求预约金", value: 4 },
               { label: "培训视频", value: 5 },
                { label: "选合作方", value: 6 },
                { label: "直播充值", value: 7 },
            ],
            is_pay:[
               { label: "未支付", value: 0 },
               { label: "已支付", value: 1 },
            ],
            status:[
               { label: "待支付", value: 1 },
               { label: "待支付", value: 2 },
               { label: "已完成", value: 3 },
               { label: "已退款", value: 4 },
               { label: "已取消", value: 5 },
            ],
        }
    },
    watch: {
        findFormData: {
           handler(nval) {
                if (JSON.stringify(nval) != '{}') {
                    this.$nextTick(() => {
                        this.form = nval
                    })
                }
            },
            immediate: true,
            deep: false,
        },
    },
    methods: {
        // 取消按钮
        cancel() {
            this.$emit('editFormCancel')
        },

        submitForm() {
            this.$refs['form'].validate((valid, obj) => {
                if (valid) {
                    this.$emit('submitForm', this.form)
                }
            })
        },

        // 表单重置
        reset() {
            this.resetForm('form')
        }
    }
}
</script>
